Precision agriculture has emerged as a critical paradigm for sustainable food production, necessitating intelligent systems for crop yield prediction and soil nutrient monitoring. This pa-per presents a novel hybrid deep learning framework integrating Convolutional Neural Networks (CNN), Long Short-Term Memory (LSTM) networks, and self-attention mechanisms for accurate crop prediction and real-time soil nutrient analysis. The proposed system employs Internet of Things (IoT) sensors for continuous monitoring of soil parameters including nitrogen (N), phosphorus (P), potassium (K), pH, moisture content, temperature, and electrical conductivity. A comprehensive dataset comprising 12,500 agricultural samples from diverse agro-climatic zones was utilized for model training and validation. The hybrid CNN-LSTM-Attention architecture achieves a prediction accuracy of 96.8% for crop classification and a mean absolute percentage error (MAPE) of 4.2% for yield prediction, significantly outperforming conventional machine learning approaches. Experimental results demonstrate that the proposed framework reduces prediction error by 23.5% compared to standalone LSTM models and 31.2% compared to traditional Random Forest classifiers. The sys-tem provides actionable recommendations for nutrient management, contributing to optimized fertilizer application and enhanced agricultural sustainability. The integration of edge computing with cloud-based analytics enables real-time decision support for farmers, achieving latency under 500 milliseconds for prediction queries.
Introduction
Agriculture plays a critical role in global food security and employment, but modern farming faces increasing challenges such as climate variability, soil degradation, water scarcity, and inefficient resource management. Traditional farming methods that rely mainly on experience and manual observation are insufficient for handling complex, data-driven agricultural problems. Precision agriculture has emerged as a solution by combining IoT sensors, data analytics, and artificial intelligence to monitor agricultural conditions and optimize crop production.
This paper proposes an IoT-based soil nutrient monitoring and crop prediction system using a hybrid deep learning model combining CNN, LSTM, and self-attention mechanisms. The system aims to improve crop prediction accuracy and provide real-time recommendations for nutrient management. It integrates sensor-based monitoring of soil and environmental parameters with advanced machine learning techniques to analyze complex spatial and temporal patterns in agricultural data.
Existing machine learning approaches such as Support Vector Machines (SVM), Random Forest, and traditional artificial neural networks have been applied to agricultural prediction tasks, but they often struggle with complex relationships, temporal dependencies, and heterogeneous sensor data. Deep learning models, particularly CNNs and LSTMs, provide stronger capabilities for extracting patterns from agricultural data. CNNs capture spatial relationships among features, while LSTMs model long-term temporal dependencies. However, existing approaches still face limitations in feature extraction, interpretability, and adapting to changing environmental conditions. The proposed integration of attention mechanisms helps overcome these issues by allowing the model to focus on the most important features and time periods.
The major contributions of the proposed system include:
Development of an IoT-based soil monitoring framework with multiple sensors.
Creation of a hybrid CNN-LSTM-Attention deep learning architecture for crop classification and yield prediction.
Evaluation using a large agricultural dataset collected from different agro-climatic regions.
Implementation of a real-time decision-support system for nutrient management.
The system architecture consists of four major layers:
ESP32 microcontrollers with LoRa communication collect and transmit sensor data through MQTT protocols. Edge computing is used for initial data validation and anomaly detection before sending information to the cloud.
Data Processing Layer
Raw sensor data undergoes preprocessing to improve quality and consistency. The process includes:
Missing value handling using interpolation and KNN-based imputation.
Feature normalization using min-max scaling.
Outlier detection using the Interquartile Range (IQR) method.
Feature engineering through indicators such as the Nutrient Balance Index (NBI), Soil Fertility Index (SFI), and temporal statistical features.
Hybrid CNN-LSTM-Attention Model
The proposed deep learning model combines three components:
CNN module: Extracts local patterns and relationships between soil and environmental features.
LSTM module: Learns long-term dependencies from sequential agricultural data.
Self-attention mechanism: Assigns importance weights to relevant features and critical time periods.
The final prediction layer performs crop classification using softmax activation and yield prediction using regression methods.
Decision Support System
The system provides real-time recommendations for nutrient management and crop planning based on sensor data and model predictions.
The experimental evaluation uses a dataset containing 12,500 agricultural samples collected from 45 monitoring stations across three agro-climatic zones over 36 months (2021–2023). The dataset includes five major crops:
Rice
Wheat
Maize
Cotton
Soybean
The proposed model was compared against several machine learning and deep learning approaches, including Random Forest, SVM, ANN, LSTM, and CNN-LSTM models. Performance was measured using accuracy, precision, recall, F1-score, AUC, and Mean Absolute Percentage Error (MAPE).
The proposed CNN-LSTM-Attention model achieved the best performance, obtaining:
96.8% classification accuracy
0.965 precision
0.962 recall
0.963 F1-score
0.97 AUC
4.2% MAPE for yield prediction
Compared with traditional methods, the proposed model improved accuracy by:
11% over Random Forest.
17.3% over SVM.
8.6% over ANN.
6% over standalone LSTM.
3.5% over CNN-LSTM without attention.
The attention mechanism significantly improved performance by identifying important agricultural factors and critical growth periods. Feature analysis showed that:
Nitrogen was the most influential factor with an importance score of 0.18.
Potassium contributed 0.14.
Rainfall contributed 0.13.
Phosphorus contributed 0.12.
The IoT monitoring system achieved reliable operation with 98.5% uptime, while edge processing reduced unnecessary cloud transmission by approximately 35%. The deployed system achieved real-time performance with inference latency below 500 milliseconds, making it suitable for practical agricultural applications.
The study demonstrates that combining IoT-based sensing with hybrid deep learning models can significantly improve crop prediction and nutrient management. The CNN-LSTM-Attention architecture effectively captures spatial patterns, temporal dependencies, and important agricultural features, leading to improved prediction accuracy and decision support.
However, the study has some limitations. The dataset is limited to specific geographic and climatic regions, which may reduce generalization to other agricultural environments. Future research should explore transfer learning techniques, larger multi-region datasets, and more interpretable prediction methods. Developing farmer-friendly interfaces with simple explanations of AI recommendations would further improve practical adoption.
Conclusion
This paper presented a comprehensive framework for crop prediction and soil nutrient monitoring using hybrid deep learning. The proposed CNN-LSTM-Attention architecture achieves state-of-the-art performance with 96.8% classification accuracy and 4.2% MAPE for yield prediction, significantly outperforming conventional approaches. The integration of IoT-based sensing with cloud analytics enables real-time decision support for nutrient management and crop selection.
Key contributions include the novel architecture combining spatial feature extraction, temporal modeling, and adaptive attention mechanisms, along with a practical deployment frame-work achieving sub-500ms latency for prediction queries. The system provides actionable recommendations for fertilizer application, contributing to agricultural sustainability and re-source optimization.
Future research directions include extension to additional crop categories and pest/disease prediction, integration of satellite imagery for spatial analysis, development of federated learning approaches for privacy-preserving model up-dates, and exploration of reinforcement learning for adaptive nutrient management strategies.
References
[1] FAO, “The State of Food and Agriculture 2023,” Food and Agriculture Organization of the United Nations, Rome, 2023.
[2] T. Wheeler and J. von Braun, “Climate change impacts on global food security,” Science, vol. 341, no. 6145, pp. 508–513, 2013.
[3] K. G. Liakos, P. Busato, D. Moshou, S. Pearson, and
[4] D. Bochtis, “Machine learning in agriculture: A review,” Sensors, vol. 18, no. 8, p. 2674, 2018.
[5] S. Wolfert, L. Ge, C. Verdouw, and M.-J. Bogaardt, “Big data in smart farming–a review,” Agricultural Systems, vol. 153, pp. 69–80, 2017.
[6] X. Shi, D. An, D. Bao, et al., “State of the art of IoT in smart agriculture,” Internet of Things, vol. 11, pp. 100–115, 2019.
[7] C. Jones and J. Jacobsen, “Plant nutrition and soil fer-tility,” Nutrient Management Module, vol. 2, pp. 1–12, 2012.
[8] T. van Klompenburg, A. Kassahun, and C. Catal, “Crop yield prediction using machine learning: A systematic literature review,” Computers and Electronics in Agricul-ture, vol. 177, p. 105709, 2020.
[9] A. Chlingaryan, S. Sukkarieh, and B. Whelan, “Machine learning approaches for crop yield prediction,” Biosys-tems Engineering, vol. 166, pp. 191–207, 2018.
[10] S. Khaki and L. Wang, “Crop yield prediction using deep neural networks,” Frontiers in Plant Science, vol. 10, p. 621, 2020.
[11] P. Nevavuori, N. Narra, and T. Lipping, “Crop yield prediction with deep convolutional neural networks,” Computers and Electronics in Agriculture, vol. 163, p. 104859, 2019.
[12] A. Vaswani, N. Shazeer, N. Parmar, et al., “Attention is all you need,” Advances in Neural Information Process-ing Systems, vol. 30, 2017.
[13] A. Kamilaris and F. X. Prenafeta-Boldú, “Deep learning in agriculture: A survey,” Computers and Electronics in Agriculture, vol. 147, pp. 70–90, 2018.
[14] M. Roopaei, P. Rad, and K.-K. R. Choo, “Cloud of things in smart agriculture,” IEEE Cloud Computing, vol. 4, no. 1, pp. 66–73, 2017.
[15] J. Muangprathub, N. Boonnam, S. Kajornkasirat, et al., “IoT and agriculture data analysis for smart farm,” Com-puters and Electronics in Agriculture, vol. 156, pp. 467–474, 2019.
[16] J. Sun, L. Di, Z. Sun, Y. Shen, and Z. Lai, “County-level soybean yield prediction using deep CNN-LSTM model,” Sensors, vol. 19, no. 20, p. 4363, 2019.
[17] V. S. F. Garnot and L. Landrieu, “Satellite image time series classification with pixel-set encoders and tempo-ral self-attention,” in Proc. IEEE/CVF CVPR, 2020, pp. 12325–12334.